package acwing.数学;

/**
 * 分解质因数
 *
 * @author yang
 * @date 2021/12/20
 */
public class 分解质因数 {

    public static void main(String[] args) {

        分解质因数.prime1(10000);
    }

    public static void prime(int n){

        for (int i = 2; i <= n / i; i++) {
            int a = 0, b = 0;
            while (n % i == 0) {
                a = i;
                n /= i;
                b++;
            }
            if (b > 0) {
                System.out.println(a + " " + b);
            }
        }
        if(n > 1) System.out.println(n + " " + 1);
    }


    public static void prime1(int n) {
        StringBuffer sb = new StringBuffer(n+"=");

        for (int i = 2; i <= n / i; i++) {
            int a = 0, b = 0;
            while (n % i == 0) {
                a = i;
                n /= i;
                b++;
            }
            if (b > 1) {
                sb.append(a);
                for (int y = 0; y < b - 1; y++) {
                    sb.append("*"+a);
                }
            }
            if (b == 1) {
                if (sb.length() == 3) {
                    sb.append(a);
                } else {
                    sb.append("*"+a);
                }

            }
        }
        if(n > 1) {
            sb.append("*"+n);
        }

    }
}
//2 1
//        3 1
//        5 1